package com.vlong.town.service.goods;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vlong.town.entity.goods.GoodsInfo;
import com.vlong.town.mapper.goods.GoodsInfoMapper;

/**
 * 本地特产信息业务实现类
 * @author Assassin
 */
@Service
public class GoodsInfoService {

    // Fields

    @Autowired
    private GoodsInfoMapper goodsInfoMapper;// 本地特产信息Mapper接口

    // Methods

    /**
     * 添加本地特产信息
     * @param townId 村镇Id
     * @param type 本地特产类型
     * @param title 本地特产标题
     * @param content 本地特产内容
     * @param desc 本地特产简介
     * @param thumbnail 缩略图
     * @param feature 本地特产特征
     */
    @Transactional
    public void add(Long townId, Integer type, String title, String content, String desc, String thumbnail, String feature,Long goodsTypeId) {
        GoodsInfo goodsInfo = new GoodsInfo();
        goodsInfo.setTownId(townId);
        goodsInfo.setState(1);
        goodsInfo.setStatus(1);
        goodsInfo.setType(type);
        goodsInfo.setTitle(title);
        goodsInfo.setContent(content);
        goodsInfo.setDesc(desc);
        goodsInfo.setThumbnail(thumbnail);
        goodsInfo.setFeature(feature);
        Long cuTime = System.currentTimeMillis();
        goodsInfo.setCreateTime(cuTime);
        goodsInfo.setUpdateTime(cuTime);
        goodsInfo.setGoodsTypeId(goodsTypeId);
        this.goodsInfoMapper.insert(goodsInfo);
    }

    /**
     * 逻辑删除本地特产信息
     * @param goodsId 主键值
     */
    @Transactional
    public void delete(Long goodsId) {
        this.goodsInfoMapper.delete(goodsId);
    }

    /**
     * 修改本地特产信息
     * @param goodsId 本地特产Id
     * @param title 本地特产标题
     * @param content 本地特产内容
     * @param desc 本地特产简介
     * @param thumbnail 缩略图
     * @param feature 本地特产特征
     */
    @Transactional
    public void update(Long goodsId, String title, String content, String desc, String thumbnail, String feature,Long goodsTypeId) {
        GoodsInfo goodsInfo = new GoodsInfo();
        goodsInfo.setGoodsId(goodsId);
        goodsInfo.setTitle(title);
        goodsInfo.setContent(content);
        goodsInfo.setDesc(desc);
        goodsInfo.setThumbnail(thumbnail);
        goodsInfo.setFeature(feature);
        goodsInfo.setUpdateTime(System.currentTimeMillis());
        goodsInfo.setGoodsTypeId(goodsTypeId);
        this.goodsInfoMapper.update(goodsInfo);
    }

    /**
     * 主键查询本地特产信息
     * @param goodsId 本地特产Id
     * @return
     */
    @Transactional(readOnly = true)
    public GoodsInfo queryById(Long goodsId) {
        return this.goodsInfoMapper.selectById(goodsId);
    }

    /**
     * 查询本地特产信息
     * @param type 特产类型
     * @param title 本地特产标题
     * @param content 本地特产内容
     * @param desc 本地特产简介
     * @return List<GoodsInfo>
     */
    @Transactional(readOnly = true)
    public List<GoodsInfo> queryList(Integer type, String title, String content, String desc,Long goodsTypeId) {
        GoodsInfo goodsInfo = new GoodsInfo();
        goodsInfo.setType(type);
        goodsInfo.setTitle(title);
        goodsInfo.setContent(content);
        goodsInfo.setDesc(desc);
        goodsInfo.setGoodsTypeId(goodsTypeId);
        return this.goodsInfoMapper.selectList(goodsInfo);
    }

}
